package network3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;

public class send {
    public static void main(String[] args) throws SocketException {
        //创建发送端的socket对象
        DatagramSocket socket = new DatagramSocket();
        //封装键盘输入数据
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String lines=null;
        try {
            while ((lines=reader.readLine())!=null){
                if ("886".equals(lines)){
                    System.out.println("数据输入结束");
                    break;
                }
                //创建数据包
                byte[] bytes = lines.getBytes();
                DatagramPacket packet = new DatagramPacket
                        (bytes, bytes.length, InetAddress.getByName("127.0.0.1"),12345);
                //发送数据
                socket.send(packet);
            }
            //释放资源
            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
